from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
from sqlalchemy.orm import sessionmaker

# 延迟导入避免循环依赖
def get_settings():
    from app.core.config import settings
    return settings

def get_engine():
    settings = get_settings()
    return create_async_engine(settings.DATABASE_URL, echo=True)

engine = get_engine()
AsyncSessionLocal = sessionmaker(
    bind=engine, class_=AsyncSession, expire_on_commit=False
)

# 依赖项
async def get_db():
    async with AsyncSessionLocal() as session:
        yield session
